package com.jiantong.work.impl.dao;

import com.google.common.collect.Maps;
import com.jiantong.work.model.DisinfectReport;
import io.terminus.common.model.Paging;
import io.terminus.common.mysql.dao.MyBatisDao;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * Created by maowenjie on 2017/3/29.
 */
@Repository
public class DisinfectReportDao extends MyBatisDao<DisinfectReport> {
    /**
     *
     * @param id 主 键
     * @return 状态
     */
    public Integer findStatusById(Long id){
        return getSqlSession().selectOne(sqlId("findStatusById"),id);
    }

    /**
     * 政府端按从日期、到日期和养殖场名称查询本市养殖场生产记录列表
     */
    public Paging<DisinfectReport> pagingDisinfectReportGqv(Integer offset, Integer limit, Map<String, Object> criteria) {
        if (criteria == null) {
            criteria = Maps.newHashMap();
        }
        Long total = (Long) getSqlSession().selectOne(sqlId("countDisinfectReportGov"), criteria);
        if (total <= 0L) {
            return new Paging<>(0L, Collections.emptyList());
        } else {
            criteria.put("offset", offset);
            criteria.put("limit", limit);
            List<DisinfectReport> data = getSqlSession().selectList(sqlId("pagingDisinfectReportGov"), criteria);
            return new Paging<>(total, data);
        }
    }

    /**
     * 返回当前单据的编码的最大值
     * @param number 除去流水号的前缀
     * @return string
     */
    public String findCurrentMaxNumber(String number){
        return getSqlSession().selectOne(sqlId("findCurrentMaxNumber"),number);
    }

    public Integer countDisinfectForWeb(Map<String, Object> map) {
        return getSqlSession().selectOne(sqlId("countDisinfectForWeb"),map);
    }

    public List<Map<String , Object>> findDisinfectInfoForWeb(Map<String, Object> map) {

        return getSqlSession().selectList(sqlId("findDisinfectInfoForWeb"),map);
    }
}